<template>
  <div class="app-container home">
    <el-row :gutter="24">
      <el-col :xs="24" :sm="24" :md="12">
        <el-card class="update-log">
          <div slot="header" class="clearfix">
            <span>义工人数统计</span>
          </div>
          <div class="body" style="display:flex;align-content: center;justify-content: center">
            <div id="myChart" :style="{width: '300px', height: '500px'}"></div>
          </div>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="24" :md="12">
        <el-card class="update-log">
          <div slot="header" class="clearfix">
            <span>义工人数统计</span>
            &nbsp;&nbsp;
            <el-date-picker
              v-model="qryMonth"
              type="month"
              placeholder="查询日期"
            >
            </el-date-picker>
          </div>

          <div class="body" style="display:flex;align-content: center;justify-content: center">
            <div id="peronDateChart" :style="{width: '500px', height: '500px'}"></div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {
  getDataInfo
} from '@/api/index/index'

export default {
  name: 'Index',
  data() {
    return {
      // 版本号
      version: '3.7.0',
      infoData: null,
      personStatus: [],
      qryMonth: ''
    }
  },
  methods: {

    getDataInfoInit() {
      let _this = this
      getDataInfo().then((resp) => {

        let finalResult = []
        resp.data.forEach(i => {
          let temp = {}
          if (this.personStatus) {
            this.personStatus.forEach(status => {
              if (i.type == status.dictValue) {
                temp.value = i.count
                temp.name = status.dictLabel
                finalResult.push(temp)
              }
            })
          }
        })
        _this.infoData = finalResult
        _this.drawLine()
      })

    },

    getPeronDateCount() {


      let _this = this
      let myChart = _this.$echarts.init(document.getElementById('peronDateChart'))

      var option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        legend: {},
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: 'Direct',
            type: 'bar',
            emphasis: {
              focus: 'series'
            },
            data: [320, 332, 301, 334, 390, 330, 320]
          },
          {
            name: 'Email',
            type: 'bar',
            stack: 'Ad',
            emphasis: {
              focus: 'series'
            },
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: 'Union Ads',
            type: 'bar',
            stack: 'Ad',
            emphasis: {
              focus: 'series'
            },
            data: [220, 182, 191, 234, 290, 330, 310]
          },
          {
            name: 'Video Ads',
            type: 'bar',
            stack: 'Ad',
            emphasis: {
              focus: 'series'
            },
            data: [150, 232, 201, 154, 190, 330, 410]
          },
          {
            name: 'Baidu',
            type: 'bar',
            barWidth: 5,
            stack: 'Search Engine',
            emphasis: {
              focus: 'series'
            },
            data: [620, 732, 701, 734, 1090, 1130, 1120]
          },
          {
            name: 'Google',
            type: 'bar',
            stack: 'Search Engine',
            emphasis: {
              focus: 'series'
            },
            data: [120, 132, 101, 134, 290, 230, 220]
          }
        ]
      }

      myChart.setOption(option)

    },

    goTarget(href) {
      window.open(href, '_blank')
    },

    drawLine() {
      let _this = this
      let myChart = this.$echarts.init(document.getElementById('myChart'))

      var option = {
        tooltip: {
          trigger: 'item'
        },
        legend: {
          top: '5%',
          left: 'center'
        },
        series: [
          {
            name: '义工状态统计',
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 2
            },
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: '40',
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: this.infoData
          }
        ]
      }
      myChart.setOption(option)
    },
    initData() {
      this.getDicts('person_status').then((response) => {
        this.personStatus = response.data
        console.log(this.personStatus)
      })
    }
  },
  mounted() {
    this.initData()
    this.getDataInfoInit()
    this.getPeronDateCount()
    var date = new Date() // Sat Jul 06 2019 19:59:27 GMT+0800 (中国标准时间)
    var year = date.getFullYear() // 2019
    var month = date.getMonth() + 1 // 7
    this.qryMonth = year + '-' +month;
  },

  watch:{
    'qryMonth'(newValue){
      console.log(newValue)
    }
  }
}
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }

  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }

  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>

